<?php
/*
中介表查询方法
selectBank($where,$order)
addBank($data)
*/

namespace Home\Model;
use Think\Model;
class AgentModel extends Model{

//查询bank
  public function selectAgent($where,$p,$n){
    $agents = $this->where($where)->page($p.','.$n)->order('agent_id desc')->select();
    if($agents){
      return $agents;
    }
    else{
      return false;
    }
  }

//添加agent
  public function addAgent($data){
    $res = $this->add($data);
    if($res){
      return $res;
    }
    else{
      return false;
    }
  }

  //根据id查询
  public function findData($id){
    $res = $this->where(array('agent_id'=>$id))->find();
    return $res;
  }

//根据条件查询是否有相同的
  public function findSameAgent($val,$id){
    if(!$id ){
      $agent = $this->where(array('company_name'=>$val,'isdel'=>'0'))->find();
    }
    if($val && $id){
      $agent = $this->where(array('company_name'=>$val , 'agent_id'=>array('neq',$id) ,'isdel'=>'0'))->find();
    }
    if($agent){
      return $agent;
    }
    else{
      return false;
    }

  }

//保存修改
  public function saveAgent($id,$data){
    $agent = $this->where(array('agent_id'=>$id))->save($data);
    if($agent){
      return ture;
    }
    else{
      return false;
    }
  }

  //查询数据条数
  public function countAgent($where){
    $num  = $this->where($where)->count();
    return $num;
  }














}
